package com.janj.bean;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;

//测试类: 查询单独的一条记录,根据id查询信息
public class Test2 {
    public static void main(String[] args) throws Exception{
        //1.读取资源文件 核心配置文件 MyBatisConfig.xml
        InputStream is = Resources.getResourceAsStream("MyBatisConfig.xml");

        //2.工厂对象
        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(is);

        //3.操作对象
        SqlSession session = factory.openSession();

        //4.执行sql
        Student stu = session.selectOne("StudentMapper.selectOne", 1);

        //5.处理结果
        System.out.println("stu = " + stu);

        //6.释放资源
       is.close();
       session.close();
    }
}
